﻿using System;
using ePipe;
using System.Runtime.InteropServices;
using Letter.IO.Scheduler;

namespace Letter.Net;

public static class SchedulerUtil
{
    private static bool dispatchSocketCallbacks = RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows) &&
                                          (Environment.GetEnvironmentVariable("DOTNET_ThreadPool_UsePortableThreadPoolForIO") == "0" ||
                                           Environment.GetEnvironmentVariable("COMPlus_ThreadPool_UsePortableThreadPoolForIO") == "0");

    public static PipeScheduler SelectSocketsScheduler()
    {
        return dispatchSocketCallbacks ? SchedulerProvider.CreateSingleScheduler() : PipeScheduler.Inline;
    }
}
